package com.sltx.controller;

import com.sltx.controller.base.BaseController;
import com.sltx.util.Conversion;
import com.sltx.util.PageData;
import net.sf.json.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.util.*;

@Controller
@ResponseBody
@RequestMapping("/json")
public class JsonController extends BaseController {


    @Value("${token-key}")
    private String token_key;

    @RequestMapping("/download")
    public Object Json(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        Map<String, Object> map = new HashMap<>();
        PageData pd = this.getPageData();
        pd.put("entName", Conversion.codeConversion(pd.get("entName").toString()));//企业名称
        pd.put("pageSize", Conversion.codeConversion(pd.get("pageSize").toString()));//每页个数
        pd.put("pageNo", Conversion.codeConversion(pd.get("pageNo").toString()));//当前页
        pd.put("reportDate", Conversion.codeConversion(pd.get("reportDate").toString()));//年报年份
        pd.put("type", Conversion.codeConversion(pd.get("type").toString()));//年报年份 查询模式（选填）：0出口，1进口


        //企业基本信息
        JSONObject getRegisterInfo = Conversion.getServiceData("getRegisterInfo", pd);
        List<Map<String, Object>> RegisterInfo = getRegisterInfo.getJSONArray("RESULTDATA");
        map.put("企业基本信息", RegisterInfo);

        //企业股东及出资信息(带每页个数和当前页)
        JSONObject getShareHolderInfo = Conversion.getServiceData("getShareHolderInfo", pd);
        List<Map<String, Object>> ShareHolderInfo = getShareHolderInfo.getJSONArray("RESULTDATA");
        ArrayList<Object> objects4 = new ArrayList<>();
        for (Map<String, Object> objectMap : ShareHolderInfo) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("INV", objectMap.get("INV"));//股东名称
            map1.put("SHXYDM", objectMap.get("SHXYDM"));//统一社会信用代码
            map1.put("INVTYPE", objectMap.get("INVTYPE"));//股东类型
            map1.put("SUBCONAM", objectMap.get("SUBCONAM"));//认缴出资额
            map1.put("CONCUR", objectMap.get("CONCUR"));//出资币种
            map1.put("CONRATIO", objectMap.get("CONRATIO"));//出资比例
            map1.put("CONDATE", objectMap.get("CONDATE"));//出资时间
            map1.put("ENTNAME", pd.get("entName"));//企业名称
            objects4.add(map1);
        }
        map.put("企业股东及出资信息", objects4);

        //主要管理人员信息(带每页个数和当前页)---企业主要管理人员
        JSONObject getMainManagerInfo = Conversion.getServiceData("getMainManagerInfo", pd);
        List<Map<String, Object>> MainManagerInfo = getMainManagerInfo.getJSONArray("RESULTDATA");
        objects4 = new ArrayList<>();
        for (Map<String, Object> mg : MainManagerInfo) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("NAME", mg.get("NAME"));//姓名
            map1.put("POSITION", mg.get("POSITION"));//职务
            map1.put("ISFRDB", mg.get("ISFRDB"));//是否法定代表人
            map1.put("ENTNAME", pd.get("entName"));//企业名称
            objects4.add(map1);
        }
        map.put("主要管理人员信息", objects4);

        //企业变更信息(带每页个数和当前页)
        JSONObject getRegisterChangeInfo = Conversion.getServiceData("getRegisterChangeInfo", pd);
        List<Map<String, Object>> RegisterChangeInfo = getRegisterChangeInfo.getJSONArray("RESULTDATA");
        objects4 = new ArrayList<>();
        for (Map<String, Object> objectMap : RegisterChangeInfo) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("ALTITEM", objectMap.get("ALTITEM"));//变更事项
            map1.put("ALTBE", objectMap.get("ALTBE"));//变更前内容
            map1.put("ALTAF", objectMap.get("ALTAF"));//变更后内容
            map1.put("ALTDATE", objectMap.get("ALTDATE"));//变更时间
            map1.put("ENTNAME", pd.get("entName"));//企业名称
            objects4.add(map1);
        }
        map.put("企业变更信息", objects4);

        //企业分支机构(带每页个数和当前页)
        JSONObject getBranchInfo = Conversion.getServiceData("getBranchInfo", pd);
        List<Map<String, Object>> BranchInfo = getBranchInfo.getJSONArray("RESULTDATA");
        objects4 = new ArrayList<>();
        for (Map<String, Object> objectMap : BranchInfo) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("FZENTNAME", objectMap.get("ENTNAME"));//分支机构名称
            map1.put("SHXYDM", objectMap.get("SHXYDM"));//统一社会信用代码
            map1.put("FRDB", objectMap.get("FRDB"));//负责人
            map1.put("ESDATE", objectMap.get("ESDATE"));//成立日期
            map1.put("ENTSTATUS", objectMap.get("ENTSTATUS"));//经营状态
            map1.put("PROVINCE", objectMap.get("PROVINCE"));//登记地省份
            map1.put("ENTNAME", pd.get("entName"));//企业名称
            objects4.add(map1);
        }
        map.put("企业分支机构", objects4);

        //企业对外投资信息(带每页个数和当前页)
        JSONObject getInvestmentAbroadInfo = Conversion.getServiceData("getInvestmentAbroadInfo", pd);
        List<Map<String, Object>> InvestmentAbroadInfo = getInvestmentAbroadInfo.getJSONArray("RESULTDATA");
        objects4 = new ArrayList<>();
        for (Map<String, Object> objectMap : InvestmentAbroadInfo) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("BTENTNAME", objectMap.get("ENTNAME"));//被投企业名称
            map1.put("SHXYDM", objectMap.get("SHXYDM"));//统一社会信用代码
            map1.put("ESDATE", objectMap.get("ESDATE"));//成立日期
            map1.put("ENTSTATUS", objectMap.get("ENTSTATUS"));//经营状态
            map1.put("REGCAP", objectMap.get("REGCAP"));//注册资本
            map1.put("SUBCONAM", objectMap.get("SUBCONAM"));//认缴出资额
            map1.put("CONCUR", objectMap.get("CONCUR"));//出资币种
            map1.put("CONRATIO", objectMap.get("CONRATIO"));//出资比例
            map1.put("CONDATE", objectMap.get("CONDATE"));//出资时间
            map1.put("ENTNAME", pd.get("entName"));//企业名称
            objects4.add(map1);
        }
        map.put("企业对外投资信息", objects4);

        //历史退出股东(带每页个数和当前页)
        JSONObject getHistoryStockHolderInfo = Conversion.getServiceData("getHistoryStockHolderInfo", pd);
        List<Map<String, Object>> HistoryStockHolderInfo = getHistoryStockHolderInfo.getJSONArray("RESULTDATA");
        objects4 = new ArrayList<>();
        for (Map<String, Object> objectMap : HistoryStockHolderInfo) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("INVNAME", objectMap.get("INVNAME"));//股东名称
            map1.put("INVTYPE", objectMap.get("INVTYPE"));//股东类型
            map1.put("DATEIN", objectMap.get("DATEIN"));//进入时间
            map1.put("DATEOUT", objectMap.get("DATEOUT"));//退出时间
            map1.put("ENTNAME", pd.get("entName"));//企业名称
            objects4.add(map1);
        }
        map.put("历史退出股东", objects4);

        //历史退出投资
        JSONObject getHistoryInvestmentAbroadInfo = Conversion.getServiceData("getHistoryInvestmentAbroadInfo", pd);
        List<Map<String, Object>> HistoryInvestmentAbroadInfo = getHistoryInvestmentAbroadInfo.getJSONArray("RESULTDATA");
        objects4 = new ArrayList<>();
        for (Map<String, Object> objectMap : HistoryInvestmentAbroadInfo) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("BTENTNAME", objectMap.get("ENTNAME"));//被投企业名称
            map1.put("DATEIN", objectMap.get("DATEIN"));//进入时间
            map1.put("DATEOUT", objectMap.get("DATEOUT"));//退出时间
            map1.put("ENTNAME", pd.get("entName"));//企业名称
            objects4.add(map1);
        }
        map.put("历史退出投资", objects4);

        //历史退出高管(带每页个数和当前页)
        JSONObject getHistoryPersonInfo = Conversion.getServiceData("getHistoryPersonInfo", pd);
        List<Map<String, Object>> HistoryPersonInfo = getHistoryPersonInfo.getJSONArray("RESULTDATA");
        objects4 = new ArrayList<>();
        for (Map<String, Object> objectMap : HistoryPersonInfo) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("NAME", objectMap.get("NAME"));//人员姓名
            map1.put("POSITION", objectMap.get("POSITION"));//职务
            map1.put("DATEIN", objectMap.get("DATEIN"));//进入时间
            map1.put("DATEOUT", objectMap.get("DATEOUT"));//退出时间
            map1.put("ENTNAME", pd.get("entName"));//企业名称
            objects4.add(map1);
        }
        map.put("历史退出高管", objects4);

        //企业年报基本信息(年份)
        JSONObject getEntAnnReportInfo = Conversion.getServiceData("getEntAnnReportInfo", pd);
        List<Map<String, Object>> EntAnnReportInfo = getEntAnnReportInfo.getJSONArray("RESULTDATA");
        map.put("企业年报基本信息", EntAnnReportInfo);

        //企业年报股东及出资信息(年份)
        JSONObject getEntAnnReportInvInfo = Conversion.getServiceData("getEntAnnReportInvInfo", pd);
        List<Map<String, Object>> EntAnnReportInvInfo = getEntAnnReportInvInfo.getJSONArray("RESULTDATA");
        objects4 = new ArrayList<>();
        for (Map<String, Object> objectMap : EntAnnReportInvInfo) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("SHANAME", objectMap.get("SHANAME"));//股东名称
            map1.put("CONAM", objectMap.get("CONAM"));//认缴出资额
            map1.put("CONDATE", objectMap.get("CONDATE"));//认缴出资时间
            map1.put("CONFORM", objectMap.get("CONFORM"));//认缴出资方式
            map1.put("ACCONAM", objectMap.get("ACCONAM"));//实缴出资额
            map1.put("ACCDATE", objectMap.get("ACCDATE"));//实缴出资时间
            map1.put("ACCFORM", objectMap.get("ACCFORM"));//实缴出资方式
            map1.put("CONCUR", objectMap.get("CONCUR"));//认缴出资币种
            map1.put("ACCCUR", objectMap.get("ACCCUR"));//实缴币种
            map1.put("ENTNAME", pd.get("entName"));//企业名称
            objects4.add(map1);
        }
        map.put("企业年报股东及出资信息", objects4);

        //企业年报网站网店信息(年份)
        JSONObject getEntAnnReportWebSiteInfo = Conversion.getServiceData("getEntAnnReportWebSiteInfo", pd);
        List<Map<String, Object>> EntAnnReportWebSiteInfo = getEntAnnReportWebSiteInfo.getJSONArray("RESULTDATA");
        objects4 = new ArrayList<>();
        for (Map<String, Object> objectMap : EntAnnReportWebSiteInfo) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("WEBNAME", objectMap.get("WEBNAME"));//网站（网店）名称
            map1.put("WEBURL", objectMap.get("WEBURL"));//网站（网店）网址
            map1.put("WEBTYPE", objectMap.get("WEBTYPE"));//网站网店类型
            map1.put("ENTNAME", pd.get("entName"));//企业名称
            objects4.add(map1);
        }
        map.put("企业年报网站网店信息", objects4);

        //企业年报资产信息(年份)---企业年报资产状况
        JSONObject getEntAnnReportAssetsInfo = Conversion.getServiceData("getEntAnnReportAssetsInfo", pd);
        List<Map<String, Object>> EntAnnReportAssetsInfo = getEntAnnReportAssetsInfo.getJSONArray("RESULTDATA");
        objects4 = new ArrayList<>();
        for (Map<String, Object> objectMap : EntAnnReportAssetsInfo) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("ASSGRO", objectMap.get("ASSGRO"));//资产总额
            map1.put("LIAGRO", objectMap.get("LIAGRO"));//负债总额
            map1.put("VENDINC", objectMap.get("VENDINC"));//营业总收入
            map1.put("MAIBUSINC", objectMap.get("MAIBUSINC"));//其中主营业务收入
            map1.put("PROGRO", objectMap.get("PROGRO"));//利润总额
            map1.put("NETINC", objectMap.get("NETINC"));//净利润
            map1.put("RATGRO", objectMap.get("RATGRO"));//纳税总额
            map1.put("TOTEQU", objectMap.get("TOTEQU"));//所有者权益合计
            map1.put("ENTNAME", pd.get("entName"));//企业名称
            objects4.add(map1);
        }
        map.put("企业年报资产信息", objects4);

        //企业年报对外担保信息(年份)
        JSONObject getEntAnnReportForGuaranteeInfo = Conversion.getServiceData("getEntAnnReportForGuaranteeInfo", pd);
        List<Map<String, Object>> EntAnnReportForGuaranteeInfo = getEntAnnReportForGuaranteeInfo.getJSONArray("RESULTDATA");
        objects4 = new ArrayList<>();
        for (Map<String, Object> objectMap : EntAnnReportForGuaranteeInfo) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("ZQR", objectMap.get("ZQR"));//债权人
            map1.put("ZWR", objectMap.get("ZWR"));//债务人
            map1.put("ZQZL", objectMap.get("ZQZL"));//主债权种类
            map1.put("ZQSE", objectMap.get("ZQSE"));//主债权数额
            map1.put("ZQQXFROM", objectMap.get("ZQQXFROM"));//履行债务的期限自
            map1.put("ZQQXTO", objectMap.get("ZQQXTO"));//履行债务的期限至
            map1.put("BZQJ", objectMap.get("BZQJ"));//保证的期间
            map1.put("BZFS", objectMap.get("BZFS"));//保证的方式
            map1.put("ENTNAME", pd.get("entName"));//企业名称
            objects4.add(map1);
        }
        map.put("企业年报对外担保信息", objects4);

        //企业商标信息(带每页个数和当前页)--企业商标列表
        JSONObject getTrademarkInfo = Conversion.getServiceData("getTrademarkInfo", pd);
        List<Map<String, Object>> TrademarkInfo = getTrademarkInfo.getJSONArray("RESULTDATA");
        objects4 = new ArrayList<>();
        for (Map<String, Object> objectMap : TrademarkInfo) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("MARKNAME", objectMap.get("MARKNAME"));//商标名称
            map1.put("APPDATE", objectMap.get("APPDATE"));//申请日期
            map1.put("UNIONTYPE", objectMap.get("UNIONTYPE"));//国际分类
            map1.put("UNIONTYPENAME", objectMap.get("UNIONTYPENAME"));//国际分类名称
            map1.put("TYPEDETAILDES", objectMap.get("TYPEDETAILDES"));//商品服务列表
            map1.put("BEGINDATE", objectMap.get("BEGINDATE"));//专用期起
            map1.put("ENDDATE", objectMap.get("ENDDATE"));//专用期止
            map1.put("CHECKDATE", objectMap.get("CHECKDATE"));//初审公告日期
            map1.put("REGDATE", objectMap.get("REGDATE"));//注册公告日期
            map1.put("MARKTYPE", objectMap.get("MARKTYPE"));//商标类型
            map1.put("MARKIMAGE", objectMap.get("MARKIMAGE"));//商标图片
            map1.put("NOTE", objectMap.get("NOTE"));//是否共有商标
            map1.put("TYPEDETAIL", objectMap.get("TYPEDETAIL"));//类似群
            map1.put("MARKCODE_KEY", objectMap.get("MARKCODE_KEY"));//注册号
            map1.put("ISINVALID", objectMap.get("ISINVALID"));//状态
            map1.put("ISCOLOR", objectMap.get("ISCOLOR"));//指定颜色
            map1.put("AGENTNAME", objectMap.get("AGENTNAME"));//代理机构
            map1.put("REGVOLUMN", objectMap.get("REGVOLUMN"));//注册公告期
            map1.put("CHECKVOLUMN", objectMap.get("CHECKVOLUMN"));//初审公告期
            map1.put("LIUCHENG", objectMap.get("LIUCHENG"));//商标流程
            map1.put("LIUCHENGDATE", objectMap.get("LIUCHENGDATE"));//流程日期
            map1.put("ADDR", objectMap.get("ADDR"));//申请人中文地址
            map1.put("FSTAPPDATE", objectMap.get("FSTAPPDATE"));//优先权时间
            map1.put("ENTNAME", pd.get("entName"));//企业名称
            objects4.add(map1);
        }
        map.put("企业商标信息", objects4);

        //企业股权出质信息(带每页个数和当前页)---企业股权出质列表+企业股权出质详情
        JSONObject getEquityPledgedInfo = Conversion.getServiceData("getEquityPledgedInfo", pd);
        List<Map<String, Object>> maps = new ArrayList<>();
        List<Map<String, Object>> EquityPledgedInfo = getEquityPledgedInfo.getJSONArray("RESULTDATA");
        if (!EquityPledgedInfo.isEmpty()) {
            for (Map<String, Object> eq : EquityPledgedInfo) {
                Map<String, Object> map1 = new HashMap<>();
                map1.put("ENTNAME", pd.get("entName"));//企业名称
                map1.put("GSRQ", eq.get("GSRQ"));//公示日期
                map1.put("DJBH", eq.get("DJBH"));//登记编号
                map1.put("CZR", eq.get("CZR"));//出质人
                map1.put("CZRZJHM", eq.get("CZRZJHM"));//出质人证照/证件号码
                map1.put("CZGQSE", eq.get("CZGQSE"));//出质股权数额
                map1.put("ZQR", eq.get("ZQR"));//质权人
                map1.put("ZQRZJHM", eq.get("ZQRZJHM"));//质权人证照/证件号码
                map1.put("GQCZSLDJRQ", eq.get("GQCZSLDJRQ"));//股权出质设立登记日期
                map1.put("ZT", eq.get("ZT"));//状态
                //获取统一社会信用代码
                for (Map<String, Object> objectMap : RegisterInfo) {
                    map1.put("CHANGE", objectMap.get("SHXYDM"));
                }
                //获取注册号
                for (Map<String, Object> objectMap : TrademarkInfo) {
                    map1.put("MARKCODE_KEY", objectMap.get("MARKCODE_KEY"));
                }
                if (!eq.get("ROWKEY").toString().isEmpty()) {
                    pd.put("rowKey", eq.get("ROWKEY"));
                    //调用企业股权出质详情接口
                    JSONObject getEquityPledgedDetailInfo = Conversion.getServiceData("getEquityPledgedDetailInfo", pd);
                    Map<String, Object> EquityPledgedDetailInfo = (Map<String, Object>) getEquityPledgedDetailInfo.get("RESULTDATA");
                    map1.put("CANCEL", EquityPledgedDetailInfo.get("CANCEL"));
                    map1.put("CHANGE", EquityPledgedDetailInfo.get("CHANGE"));
                }
                maps.add(map1);
            }
        }
        map.put("企业股权出质信息", maps);


        //企业动产抵押信息(带每页个数和当前页)---企业动产抵押列表+企业动产抵押详情
        JSONObject getChattelMortgageInfo = Conversion.getServiceData("getChattelMortgageInfo", pd);
        List<Map<String, Object>> ChattelMortgageInfo = getChattelMortgageInfo.getJSONArray("RESULTDATA");
        List<Map<String, Object>> maps1 = new ArrayList<>();
        if (!ChattelMortgageInfo.isEmpty()) {
            for (Map<String, Object> cm : ChattelMortgageInfo) {
                Map<String, Object> map1 = new HashMap<>();
                map1.put("ENTNAME", pd.get("entName"));//企业名称
                map1.put("DJBH", cm.get("DJBH"));//登记编号
                map1.put("DJRQ", cm.get("DJRQ"));//登记日期
                map1.put("DJJG", cm.get("DJJG"));//登记机关
                map1.put("BDBZQSE", cm.get("BDBZQSE"));//被担保债权数额
                map1.put("ZT", cm.get("ZT"));//状态
                map1.put("GSRQ", cm.get("GSRQ"));//公示日期
                //获取统一社会信用代码
                for (Map<String, Object> objectMap : RegisterInfo) {
                    map1.put("CHANGE", objectMap.get("SHXYDM"));
                }
                //获取注册号
                for (Map<String, Object> objectMap : TrademarkInfo) {
                    map1.put("MARKCODE_KEY", objectMap.get("MARKCODE_KEY"));
                }
                if (!cm.get("ROWKEY").toString().isEmpty()) {
                    pd.put("rowKey", cm.get("ROWKEY"));
                    //调用企业动产抵押详情接口
                    JSONObject getChattelMortgageDetailInfo = Conversion.getServiceData("getChattelMortgageDetailInfo", pd);
                    Map<String, Object> ChattelMortgageDetailInfo = (Map<String, Object>) getChattelMortgageDetailInfo.get("RESULTDATA");
                    map1.put("MORTGAGEE", ChattelMortgageDetailInfo.get("MORTGAGEE"));//抵押权人
                    map1.put("SECURED", ChattelMortgageDetailInfo.get("SECURED"));//被担保债权
                    map1.put("CANCEL", ChattelMortgageDetailInfo.get("CANCEL"));//注销
                    map1.put("CHANGE", ChattelMortgageDetailInfo.get("CHANGE"));//变更
                    map1.put("RESISTER", ChattelMortgageDetailInfo.get("RESISTER"));//登记信息
                    map1.put("PAWN", ChattelMortgageDetailInfo.get("PAWN"));//抵押物
                }
                maps1.add(map1);
            }
        }
        map.put("企业动产抵押信息", maps1);


        //企业专利信息(带每页个数和当前页)--企业专利列表+企业专利详情
        JSONObject getPatentInfo = Conversion.getServiceData("getPatentInfo", pd);
        List<Map<String, Object>> PatentInfo = getPatentInfo.getJSONArray("RESULTDATA");
        if (!PatentInfo.isEmpty()) {
            for (Map<String, Object> objectMap : PatentInfo) {
                objects4 = new ArrayList<>();
                Map<String, Object> map1 = new HashMap<>();
                map1.put("FZL_MC", objectMap.get("FZL_MC"));//专利名称
                map1.put("FZL_SQH", objectMap.get("FZL_SQH"));//申请号
                map1.put("FZL_SQR", objectMap.get("FZL_SQR"));//申请日期
                map1.put("FZL_ZLLX", objectMap.get("FZL_ZLLX"));//专利类型
                map1.put("FZL_ZFLH", objectMap.get("FZL_ZFLH"));//主分类号
                map1.put("FZL_FLH", objectMap.get("FZL_FLH"));//分类号
                map1.put("FZL_GKGGH", objectMap.get("FZL_GKGGH"));//公开（公告）号
                map1.put("FZL_GKGGR", objectMap.get("FZL_GKGGR"));//公开（公告）日
                map1.put("FZL_ZFLH_3CN", objectMap.get("FZL_ZFLH_3CN"));//专利技术领域
                map1.put("FZL_SQZLQR", objectMap.get("FZL_SQZLQR"));//申请（专利权）人
                map1.put("FZL_FMSJR", objectMap.get("FZL_FMSJR"));//发明（设计）人
                map1.put("FZL_FLZT", objectMap.get("FZL_FLZT"));//法律状态
                map1.put("FZL_VALIDITY", objectMap.get("FZL_VALIDITY"));//专利有效性
                map1.put("FZL_ZLDLJG", objectMap.get("FZL_ZLDLJG"));//专利代理机构
                map1.put("FZL_DLR", objectMap.get("FZL_DLR"));//代理人
                map1.put("FZL_DZ", objectMap.get("FZL_DZ"));//详细地址
                map1.put("FZL_YXQ", objectMap.get("FZL_YXQ"));//优先权
                map1.put("FFL_SQGGH", objectMap.get("FFL_SQGGH"));//授权号
                map1.put("ENTNAME", pd.get("entName"));//企业名称
                if (!objectMap.get("ROWKEY").toString().isEmpty()) {
                    pd.put("rowKey", objectMap.get("ROWKEY"));
                    JSONObject getPatentDetailInfo = Conversion.getServiceData("getPatentDetailInfo", pd);
                    List<Map<String, Object>> PatentDetailInfo = getPatentDetailInfo.getJSONArray("RESULTDATA");
                    map1.put("PatentDetailInfo", PatentDetailInfo);
                }
                objects4.add(map1);
            }
        }
        map.put("企业专利信息", objects4);


        //企业软件著作权信息(带每页个数和当前页)
        JSONObject getSoftwareCopyrightInfo = Conversion.getServiceData("getSoftwareCopyrightInfo", pd);
        List<Map<String, Object>> SoftwareCopyrightInfo = getSoftwareCopyrightInfo.getJSONArray("RESULTDATA");
        map.put("企业软件著作权信息", SoftwareCopyrightInfo);

        //作品著作权信息(带每页个数和当前页)
        JSONObject getWorksCopyrightInfo = Conversion.getServiceData("getWorksCopyrightInfo", pd);
        List<Map<String, Object>> WorksCopyrightInfo = getWorksCopyrightInfo.getJSONArray("RESULTDATA");
        map.put("作品著作权信息", WorksCopyrightInfo);

        //经营异常名录
        JSONObject getOperatingExceptionRota = Conversion.getServiceData("getOperatingExceptionRota", pd);
        List<Map<String, Object>> OperatingExceptionRota = getOperatingExceptionRota.getJSONArray("RESULTDATA");
        objects4 = new ArrayList<>();
        for (Map<String, Object> objectMap : OperatingExceptionRota) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("REASONIN", objectMap.get("REASONIN"));//列入经营异常名录原因
            map1.put("DATEIN", objectMap.get("DATEIN"));//列入日期
            map1.put("REGORGIN", objectMap.get("REGORGIN"));//作出决定机关（列入）
            map1.put("REASONOUT", objectMap.get("REASONOUT"));//移出经营异常名录原因
            map1.put("DATEOUT", objectMap.get("DATEOUT"));//移出日期
            map1.put("REGORGOUT", objectMap.get("REGORGOUT"));//作出决定机关（移出）
            map1.put("ISMOVE", objectMap.get("ISMOVE"));//是否移除
            map1.put("ENTNAME", pd.get("entName"));//企业名称
            objects4.add(map1);
        }
        map.put("经营异常名录", objects4);

        //企业行政处罚信息(带每页个数和当前页)
        JSONObject getLawAdminInfo = Conversion.getServiceData("getLawAdminInfo", pd);
        List<Map<String, Object>> LawAdminInfo = getLawAdminInfo.getJSONArray("RESULTDATA");
        objects4 = new ArrayList<>();
        for (Map<String, Object> objectMap : LawAdminInfo) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("PENDECNO", objectMap.get("PENDECNO"));//行政处罚决定书文号
            map1.put("ILLEGACTTYPE", objectMap.get("ILLEGACTTYPE"));//违法行为类型
            map1.put("PENRESULT", objectMap.get("PENRESULT"));//行政处罚内容
            map1.put("CASEDEP", objectMap.get("CASEDEP"));//决定机关名称
            map1.put("PENDECISSDATE", objectMap.get("PENDECISSDATE"));//处罚决定日期
            map1.put("PUBDATE", objectMap.get("PUBDATE"));//公示时间
            map1.put("ISMOVE", objectMap.get("ISMOVE"));//是否移除
            map1.put("ENTNAME", pd.get("entName"));//企业名称
            objects4.add(map1);
        }
        map.put("企业行政处罚信息", objects4);

        //法院被执行人信息(带每页个数和当前页)
        JSONObject getBePerformedInfo = Conversion.getServiceData("getBePerformedInfo", pd);
        List<Map<String, Object>> BePerformedInfo = getBePerformedInfo.getJSONArray("RESULTDATA");
        map.put("法院被执行人信息", BePerformedInfo);

        //法院失信人信息(带每页个数和当前页)
        JSONObject getLostCreditInfo = Conversion.getServiceData("getLostCreditInfo", pd);
        List<Map<String, Object>> LostCreditInfo = getLostCreditInfo.getJSONArray("RESULTDATA");
        map.put("法院失信人信息", LostCreditInfo);

        //法院公告信息
        JSONObject getCourtAnnouncementInfo = Conversion.getServiceData("getCourtAnnouncementInfo", pd);
        List<Map<String, Object>> CourtAnnouncementInfo = getCourtAnnouncementInfo.getJSONArray("RESULTDATA");
        map.put("法院公告信息", CourtAnnouncementInfo);

        //法院裁判文书信息(带每页个数和当前页)--法院裁判文书列表+法院裁判文书详情
        JSONObject getExecuteJudgmentInfo = Conversion.getServiceData("getExecuteJudgmentInfo", pd);
        List<Map<String, Object>> ExecuteJudgmentInfo = getExecuteJudgmentInfo.getJSONArray("RESULTDATA");
        List<Object> objects2 = new ArrayList<>();
        if (!ExecuteJudgmentInfo.isEmpty()) {
            for (Map<String, Object> ej : ExecuteJudgmentInfo) {
                Map<String, Object> map1 = new HashMap<>();
                map1.put("FFL_AREA", ej.get("FFL_AREA"));//地区
                map1.put("FFL_CLASS", ej.get("FFL_CLASS"));//案件类型
                map1.put("FFL_COURT", ej.get("FFL_COURT"));//执行法院
                map1.put("FFL_TITLE", ej.get("FFL_TITLE"));//标题
                map1.put("FFL_CASENUM", ej.get("FFL_CASENUM"));//案号
                map1.put("FFL_JUDGDATE", ej.get("FFL_JUDGDATE"));//审判日期
                map1.put("FFL_TIME", ej.get("FFL_TIME"));//提交时间
                if (!ej.get("ROWKEY").toString().isEmpty()) {
                    pd.put("rowKey", ej.get("ROWKEY"));
                    JSONObject getExecuteJudgmentDetailInfo = Conversion.getServiceData("getExecuteJudgmentDetailInfo", pd);
                    List<Map<String, Object>> ExecuteJudgmentDetailInfo = getExecuteJudgmentDetailInfo.getJSONArray("RESULTDATA");
                    map1.put("CONTENT", ExecuteJudgmentDetailInfo);
                }
                objects2.add(map1);
            }
        }
        map.put("法院裁判文书信息", objects2);

        //企业简介信息--企业简介信息+企业基本信息+企业LOGO
        JSONObject getEnterpriseProfileInfo = Conversion.getServiceData("getEnterpriseProfileInfo", pd);
        List<Map<String, Object>> EnterpriseProfileInfo = getEnterpriseProfileInfo.getJSONArray("RESULTDATA");
        //企业LOGO
        JSONObject getEntLogoInfo = Conversion.getServiceData("getEntLogoInfo", pd);
        List<Map<String, Object>> EntLogoInfo = getEntLogoInfo.getJSONArray("RESULTDATA");
        HashMap<Object, Object> map2 = new HashMap<>();
        for (Map<String, Object> ep : EnterpriseProfileInfo) {
            map2.put("DESCRIPTION", ep.get("DESCRIPTION"));//企业简介
        }
        for (Map<String, Object> objectMap : EntLogoInfo) {
            map2.put("LOGO", objectMap.get("LOGO"));//企业LOGO
        }
        //企业基本信息接口获取企业官网
        for (Map<String, Object> rst : RegisterInfo) {
            map2.put("WEBSITE", rst.get("WEBSITE"));//企业官网
        }

        map2.put("ENTNAME", pd.get("entName"));//企业名称
        map.put("企业简介信息", map2);

        //企业网站备案信息(带每页个数和当前页)
        JSONObject getICPRecordInfo = Conversion.getServiceData("getICPRecordInfo", pd);
        List<Map<String, Object>> ICPRecordInfo = getICPRecordInfo.getJSONArray("RESULTDATA");
        map.put("企业网站备案信息", ICPRecordInfo);

        //企业招聘需求信息(带每页个数和当前页)--企业招聘列表+企业招聘详情
        JSONObject getRecruitmentInfo = Conversion.getServiceData("getRecruitmentInfo", pd);
        List<Map<String, Object>> RecruitmentInfo = getRecruitmentInfo.getJSONArray("RESULTDATA");
        ArrayList<Object> objects1 = new ArrayList<>();
        if (!RecruitmentInfo.isEmpty()) {
            for (Map<String, Object> rt : RecruitmentInfo) {
                HashMap<String, Object> map1 = new HashMap<>();
                map1.put("FZPRH_POSITION", rt.get("FZPRH_POSITION"));//职位名称
                map1.put("FZPRH_EXPRIYEARS", rt.get("FZPRH_EXPRIYEARS"));//工作年限
                map1.put("FZPRH_EDUCATION", rt.get("FZPRH_EDUCATION"));//学历
                map1.put("FZPRH_GLJY", rt.get("FZPRH_GLJY"));//是否有管理经验
                map1.put("FZPRH_SALARY", rt.get("FZPRH_SALARY"));//薪水范围
                map1.put("FZPRH_JOBADDR", rt.get("FZPRH_JOBADDR"));//工作地点
                map1.put("FZPRH_RECRUITMENT", rt.get("FZPRH_RECRUITMENT"));//招聘人数
                map1.put("FZPRH_FUNCTION", rt.get("FZPRH_FUNCTION"));//职位职能
                map1.put("FZPRH_LAESTUPDATE", rt.get("FZPRH_LAESTUPDATE"));//职位刷新时间
                map1.put("ENTNAME", pd.get("entName"));//企业名称
                if (!rt.get("ROWKEY").toString().isEmpty()) {
                    pd.put("rowKey", rt.get("ROWKEY"));
                    JSONObject getRecruitmentDetailInfo = Conversion.getServiceData("getRecruitmentDetailInfo", pd);
                    List<Map<String, Object>> RecruitmentDetailInfo = getRecruitmentDetailInfo.getJSONArray("RESULTDATA");
                    map1.put("FZPRH", RecruitmentDetailInfo);
                }
                objects1.add(map1);
            }
        }
        map.put("企业招聘需求信息", objects1);


        //企业招投标信息(带每页个数和当前页)--企业投标列表+企业投标详情
        JSONObject getBiddingInfo = Conversion.getServiceData("getBiddingInfo", pd);
        List<Map<String, Object>> BiddingInfo = getBiddingInfo.getJSONArray("RESULTDATA");
        ArrayList<Object> objects3 = new ArrayList<>();
        if (!BiddingInfo.isEmpty()) {
            for (Map<String, Object> bd : BiddingInfo) {
                HashMap<String, Object> map1 = new HashMap<>();
                map1.put("FZE_BXQY", bd.get("FZE_BXQY"));//标讯区域
                map1.put("FZE_XZQY", bd.get("FZE_XZQY"));//地区
                map1.put("FZF_TITLE", bd.get("FZF_TITLE"));//标题
                map1.put("FZF_CGR", bd.get("FZF_CGR"));//采购人
                map1.put("FZE_DLJG", bd.get("FZE_DLJG"));//代理机构
                map1.put("FZE_ZBBH", bd.get("FZE_ZBBH"));//招标编号
                map1.put("FZE_FBDATE", bd.get("FZE_FBDATE"));//发布时间
                map1.put("ENTNAME", pd.get("entName"));//企业名称
                if (!bd.get("ROWKEY").toString().isEmpty()) {
                    pd.put("rowKey", bd.get("ROWKEY"));
                    //企业投标详情
                    JSONObject getBiddingDetailInfo = Conversion.getServiceData("getBiddingDetailInfo", pd);
                    List<Map<String, Object>> BiddingDetailInfo = getBiddingDetailInfo.getJSONArray("RESULTDATA");
                    map1.put("BiddingDetailInfo", BiddingDetailInfo);
                }
                objects3.add(map1);
            }
        }
        map.put("企业招投标信息", objects3);

        //企业进出口信息(带每页个数和当前页+type查询模式（选填）：0出口，1进口)
        JSONObject getTradeInfo = Conversion.getServiceData("getTradeInfo", pd);
        List<Map<String, Object>> TradeInfo = getTradeInfo.getJSONArray("RESULTDATA");
        map.put("企业进出口信息", TradeInfo);

        //企业网店商铺信息(带每页个数和当前页)
        JSONObject getInternetShopInfo = Conversion.getServiceData("getInternetShopInfo", pd);
        List<Map<String, Object>> InternetShopInfo = getInternetShopInfo.getJSONArray("RESULTDATA");
        objects4 = new ArrayList<>();
        for (Map<String, Object> objectMap : InternetShopInfo) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("STORE", objectMap.get("STORE"));//店铺名称
            map1.put("STOREURL", objectMap.get("STOREURL"));//店铺网址
            map1.put("PLATFORM", objectMap.get("PLATFORM"));//店铺位置
            map1.put("ENTNAME", pd.get("entName"));//企业名称
            objects4.add(map1);
        }
        map.put("企业网店商铺信息", objects4);

        //企业资质信息(带每页个数和当前页)
        JSONObject getQualifyCertifyInfo = Conversion.getServiceData("getQualifyCertifyInfo", pd);
        List<Map<String, Object>> QualifyCertifyInfo = getQualifyCertifyInfo.getJSONArray("RESULTDATA");
        objects4 = new ArrayList<>();
        for (Map<String, Object> objectMap : QualifyCertifyInfo) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("FQZ_ZZMC", objectMap.get("FQZ_ZZMC"));//资质名称
            map1.put("FQZ_ZSBH", objectMap.get("FQZ_ZSBH"));//证书编号
            map1.put("FQZ_FZRQ", objectMap.get("FQZ_FZRQ"));//发证时间
            map1.put("FQZ_JZRQ", objectMap.get("FQZ_JZRQ"));//有效期至
            map1.put("FQZ_RZJG", objectMap.get("FQZ_RZJG"));//认证机构
            map1.put("FQZ_RZNR", objectMap.get("FQZ_RZNR"));//认证内容
            map1.put("ENTNAME", pd.get("entName"));//企业名称
            objects4.add(map1);
        }
        map.put("企业资质信息", objects4);

        //企业荣誉信息(带每页个数和当前页)
        JSONObject getEntHonorInfo = Conversion.getServiceData("getEntHonorInfo", pd);
        List<Map<String, Object>> EntHonorInfo = getEntHonorInfo.getJSONArray("RESULTDATA");
        objects4 = new ArrayList<>();
        for (Map<String, Object> objectMap : EntHonorInfo) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("RYMC", objectMap.get("RYMC"));//荣誉称号
            map1.put("JGMC", objectMap.get("JGMC"));//评价机构
            map1.put("FZRQ", objectMap.get("FZRQ"));//评价年份
            map1.put("ENTNAME", pd.get("entName"));//企业名称
            objects4.add(map1);
        }
        map.put("企业荣誉信息", objects4);

        //企业地理位置信息
        JSONObject getGeoPositionInfo = Conversion.getServiceData("getGeoPositionInfo", pd);
        List<Map<String, Object>> GeoPositionInfo = getGeoPositionInfo.getJSONArray("RESULTDATA");
        objects4 = new ArrayList<>();
        for (Map<String, Object> objectMap : GeoPositionInfo) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("DOM", objectMap.get("DOM"));//实际地址
            map1.put("JWD", objectMap.get("JWD"));//地理坐标
            map1.put("ADDR_FORMAT_ADDR", objectMap.get("ADDR_FORMAT_ADDR"));//标准地址
            map1.put("ADDR_LEVEL", objectMap.get("ADDR_LEVEL"));//地址级别
            map1.put("LL_STREET_DIRECTION", objectMap.get("LL_STREET_DIRECTION"));//街道方向
            map1.put("LL_STREET_DISTANCE", objectMap.get("LL_STREET_DISTANCE"));//街道距离
            map1.put("LL_PROVINCE", objectMap.get("LL_PROVINCE"));//所在省
            map1.put("LL_CITY", objectMap.get("LL_CITY"));//所在城市
            map1.put("LL_DISTRICT", objectMap.get("LL_DISTRICT"));//所在区
            map1.put("LL_TOWNSHIP", objectMap.get("LL_TOWNSHIP"));//所在乡镇
            map1.put("LL_STREET", objectMap.get("LL_STREET"));//所在街道
            map1.put("LL_BUSINESSAREAS_NAME", objectMap.get("LL_BUSINESSAREAS_NAME"));//商圈名字
            map1.put("ENTNAME", pd.get("entName"));//企业名称
            objects4.add(map1);
        }
        map.put("企业地理位置信息", objects4);

        //企业发展纪事(带每页个数和当前页)
        JSONObject getEntChronicleInfo = Conversion.getServiceData("getEntChronicleInfo", pd);
        List<Map<String, Object>> EntChronicleInfo = getEntChronicleInfo.getJSONArray("RESULTDATA");
        objects4 = new ArrayList<>();
        for (Map<String, Object> objectMap : EntChronicleInfo) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("ACT", objectMap.get("ACT"));//动作
            map1.put("UNIT", objectMap.get("UNIT"));//单位
            map1.put("MONTH", objectMap.get("MONTH"));//年月
            map1.put("AREA", objectMap.get("AREA"));//区域
            map1.put("FIELD", objectMap.get("FIELD"));//内容项
            map1.put("NUM", objectMap.get("NUM"));//数量
            map1.put("CONTENT", objectMap.get("CONTENT"));//内容
            map1.put("DATE", objectMap.get("DATE"));//时间
            map1.put("DESCRIBE", objectMap.get("DESCRIBE"));//描述
            map1.put("ENTNAME", pd.get("entName"));//企业名称
            objects4.add(map1);
        }
        map.put("企业发展纪事", objects4);

        //企业新闻舆情信息
        String token = token_key;
        String url = "http://open.api.tianyancha.com/services/open/ps/news/2.0?";
        String name = pd.get("entName").toString();
        String pageSize = pd.get("pageSize").toString();
        String pageNum = pd.get("pageNo").toString();
        BasicHttpParams httpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParams, 1000);
        HttpConnectionParams.setSoTimeout(httpParams, 1000);
        HttpClient httpClient = new DefaultHttpClient(httpParams);
        String result = null;
        try {
            HttpGet get = new HttpGet(url + "name=" + name + "&pageNum=" + pageNum + "&pageSize=" + pageSize);
            // 设置header
            get.setHeader("Authorization", token);
            // 设置类型
            HttpResponse response = httpClient.execute(get);
            HttpEntity entity = response.getEntity();
            result = EntityUtils.toString(entity, "utf-8");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            httpClient.getConnectionManager().shutdown();
        }
        JSONObject jsonObject1 = JSONObject.fromObject(result);
        if (jsonObject1.get("result").equals(null)) {
            ArrayList<Object> objects5 = new ArrayList<>();
            map.put("企业新闻舆情信息", objects5);
        } else {
            Map<String, Object> result1 = (Map<String, Object>) jsonObject1.get("result");
            List<Map<String, Object>> list = (List<Map<String, Object>>) result1.get("items");
            map.put("企业新闻舆情信息", list);
        }

        //下载为json文件
        //将数据转换为json格式
        JSONObject jsonObject = JSONObject.fromObject(map);

        // 设置响应头以触发文件下载
        resp.setContentType("application/json;charset=UTF-8");
        //resp.setHeader("Content-Disposition", "attachment; filename=\"downloaded_data.json\"");
        resp.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + URLEncoder.encode(pd.get("entName") + ".json", "UTF-8"));

        // 写入JSON数据到响应体
        try (PrintWriter out = resp.getWriter()) {
            out.print(jsonObject);
            out.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        return jsonObject;
    }
}
